package com.meiqiongproperty.yiguanjia.fragment.order;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.meiqiongproperty.yiguanjia.R;
import com.meiqiongproperty.yiguanjia.databinding.OrderLayoutBinding;
import com.meiqiongproperty.yiguanjia.fragment.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * author: Administrator
 * date: 2017/5/13.
 * package:com.meiqiongproperty.yiguanjia.fragment.order
 */

public class OrderIndexFragment extends BaseFragment {
    OrderLayoutBinding binding;
    List<Fragment> list;
    MyAdapter adapter;
    private String[] titles = {"商城", "生活服务", "物业"};


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.order_layout, container, false);
        initNav();
        initViewPager();
        return binding.getRoot();
    }

    private void initNav(){
        binding.navigation.setTitle("全部订单");
        binding.navigation.hideLeft(true);
    }

    private void initViewPager(){
        list = new ArrayList<>();
        list.add(new OrderShoppingFragment());
        list.add(new OrderLifeServiceFragment());
        list.add(new OrderTenementFragment());

        adapter=new MyAdapter(getActivity().getSupportFragmentManager(),getActivity());
        binding.viewPager.setAdapter(adapter);
        binding.tabLayout.setupWithViewPager(binding.viewPager);
    }


    class MyAdapter extends FragmentPagerAdapter {

        private Context context;

        public MyAdapter(FragmentManager fm, Context context) {
            super(fm);
            this.context = context;
        }

        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    }
}
